/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [ScoreLogicImpl.java]
 * Creation Date        [12-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_04_other.examApp.dao.impl;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import pkg_04_other.examApp.dao.ExaminationAdapter;
import pkg_04_other.examApp.util.ExaminationUtil;

/**
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class ScoreLogicImpl extends ExaminationAdapter {

	/**
	 * 计算分数
	 */
	@Override
	public float getScore() {
		int count = 0;
		for (int i = 1; i <= super.getCorrectAnswers().size(); i++) {
			System.out.println(super.getCorrectAnswers().get(i) + "---"
					+ super.getAnswers().get(i));
			// 答对题目
			if (super.getCorrectAnswers().get(i)
					.equals(super.getAnswers().get(i))) {
				System.out.println(count);
				count++;
			}
		}
		int c = count;
		int n = super.getAnswers().size();
		float score = (c / n) * 100;
		System.out.println("你的得分为" + score);

		String fileName = "src_03_best_practices/pkg_04_other/examApp/configuration"
				+ File.separator + super.getSubject() + ".sco";
		System.out.println(fileName);
		List<String> scores = new ArrayList<String>();
		String temp = super.getId() + ":" + score;
		scores.add(temp);

		try {
			// 写出成绩
			ExaminationUtil.writeFile(scores, fileName);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return score;
	}
}
